﻿using System;
using System.Windows;
using YwangHRMSys.DAL;
using YwangHRMSys.Model;


namespace YwangHRMSys.UI.SystemMgr.DepartmentMgr
    {
        /// <summary>
        ///     DepartmentWindowEdit.xaml 的交互逻辑
        /// </summary>
        public partial class DepartmentWindowEdit : Window
            {

                public DepartmentWindowEdit()
                {
                    InitializeComponent();
                }

                public bool IsInsert { get; set; }

                public Guid EditGuid { get; set; }

                private void Window_Loaded( object sender, RoutedEventArgs e )
                {
                    //判断是否为添加。
                    if (IsInsert)
                        {

                        }
                    else
                        {
                            var dal = new DepartmentInfoDAL();

                           

                            DepartmentInfoModel departmentInfo = dal.GetByDepartmentInfoID(EditGuid);
                            DepartName.Text = departmentInfo.DepartmentName;
                        }

                }

                private void BtnAdd_Click( object sender, RoutedEventArgs e )
                {
                    var de = new DepartmentInfoModel();
                    if (IsInsert)
                        {

                            de.DepartmentName = DepartName.Text;
                        
                            new DepartmentInfoDAL().InsertDepartmentInfo(de);
                            DialogResult = true;
                        }
                    else
                        {

                            de.DepartmentName = DepartName.Text;
                            de.Id = EditGuid;
                            new DepartmentInfoDAL().UpdateDepartmentInfo(de);
                            DialogResult = true;
                        }
                }

            }
    }